/*
 * Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.security.authentication;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * indicates a class can process a specific
 * {@link org.springframework.security.core.Authentication} implementation.
 *
 * @author Ben Alex
 */
public interface AuthenticationProvider {

	/**
	 * 执行身份验证
	 * 这里会一个个遍历 AuthenticationProvider 的实现类进行认证，只要有一个认证通过，就会返回认证结果
	 *
	 * @param authentication 对象
	 * @return 身份验证后的 Authentication 对象，这个对象包含了权限信息
	 * @throws AuthenticationException（认证失败异常）
	 *         AuthenticationException 是一个抽象类，它有很多认证失败的场景（IDEA可以通过 Ctrl + H 查看实现类）
	 */
	Authentication authenticate(Authentication authentication) throws AuthenticationException;

	/**
	 * 判断当前类（AuthenticationProvider的实现类）是否支持验证传入的 authentication 对象
	 * 这个方法会在 AuthenticationProvider 的实现类 ProviderManager 里面被调用
	 */
	boolean supports(Class<?> authentication);

}
